package com.jiang.smartdangjian.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.RecyclerView;

import com.jiang.smartdangjian.R;
import com.jiang.smartdangjian.model.CommData;
import com.jiang.smartdangjian.model.NewsData;
import com.jiang.smartdangjian.tool.HttpUtil;
import com.jiang.smartdangjian.tool.MyAdapter;
import com.jiang.smartdangjian.tool.MyCallback;
import com.jiang.smartdangjian.tool.Tool;

public class NewsActivity extends BaseActivity implements View.OnClickListener {

    private ImageView imageView8;
    private WebView wv;
    private RecyclerView rv;
    private TextView textView8;
    private TextView textView9;
    private NestedScrollView ns;
    private TextView tv_none;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);
        initView();
        NewsData.RowsModel news = Tool.news;
        setTitle(news.title);
        textView8.setText(news.title);
        Tool.loadImg(news.cover, imageView8);
        wv.loadData(news.content, "text/html", "UTF-8");

        getComm();
    }

    private void getComm() {
        HttpUtil.get("/prod-api/press/comments/list?newsId=" + Tool.news.id, new MyCallback(getThis(), CommData.class) {
            @Override
            public void onFinish(Object obj) {
                CommData data = (CommData) obj;
                tv_none.setVisibility((data.rows != null && !data.rows.isEmpty()) ? View.GONE : View.VISIBLE);
                rv.setAdapter(new MyAdapter<CommData.RowsModel>(getThis(), R.layout.item_comm, data.rows) {
                    private ImageView imageView9;
                    private TextView textView10;
                    private TextView textView11;
                    private TextView textView12;

                    @Override
                    public void init(View root, int position) {
                        imageView9 = (ImageView) root.findViewById(R.id.imageView9);
                        textView10 = (TextView) root.findViewById(R.id.textView10);
                        textView11 = (TextView) root.findViewById(R.id.textView11);
                        textView12 = (TextView) root.findViewById(R.id.textView12);

                        CommData.RowsModel rowsModel = list.get(position);
                        textView10.setText("" + rowsModel.likeNum);
                        textView11.setText(rowsModel.userName);
                        textView12.setText("" + rowsModel.content);
                    }
                });
            }
        });
    }

    private void initView() {
        imageView8 = (ImageView) findViewById(R.id.imageView8);
        wv = (WebView) findViewById(R.id.wv);
        rv = (RecyclerView) findViewById(R.id.rv);
        textView8 = (TextView) findViewById(R.id.textView8);
        textView9 = (TextView) findViewById(R.id.textView9);
        ns = (NestedScrollView) findViewById(R.id.ns);

        tv_none = (TextView) findViewById(R.id.tv_none);
    }

    @Override
    public void onClick(View v) {

    }

}